package com.gitee.kenewstar.migration.entity;

import cn.hutool.core.collection.CollUtil;
import lombok.Data;

import java.util.List;

/**
 * @author kenewstar
 */
@Data
public class CommonResponse {

    private Integer totalCount;
    private Long successCount;
    private Long errorCount;
    private List<CommonResult> list;


    public void dataCompute() {
        if (CollUtil.isEmpty(list)) {
            return;
        }
        this.totalCount = list.size();
        this.successCount = list.stream().filter(x -> Boolean.TRUE.equals(x.getSuccessFlag())).count();
        this.errorCount = list.stream().filter(x -> Boolean.FALSE.equals(x.getSuccessFlag())).count();
    }

    public static CommonResponse result(List<CommonResult> list) {
        CommonResponse response = new CommonResponse();
        response.setList(list);
        response.dataCompute();
        return response;
    }

}
